package types

import (
	"reflect"
)

// Component
// is base bean implement
//
// param:
//
// - `name` define bean name
type Component struct {
	tag reflect.StructTag
}

func (c *Component) Bean() string {
	return c.getOrDefault("name")
}

func (c *Component) BeanStart() {
}

func (c *Component) BeanEnd() {
}

//func (c *Component) Init() error {
//	return nil
//}
//
//func (c *Component) Destroy() error {
//	return nil
//}

func (c *Component) SetTag(tag reflect.StructTag) {
	c.tag = tag
}

func (c *Component) GetTag(key string) (string, bool) {
	return c.tag.Lookup(key)
}

func (c *Component) getOrDefault(key string, def ...string) string {
	if tag, ok := c.GetTag(key); ok {
		return tag
	}
	if len(def) != 0 {
		return def[0]
	}
	return ""
}
